﻿using System.Collections.Generic;
using UnityEngine;

namespace LightGameLibs
{
    [System.Serializable]
    public class RichTextArg
    {
        public LocalizationTag m_content;
        public Color m_color;
        public int m_size;
        public FontStyle m_type;

        public string GetRichText(Color defaultColor, int defaultSize, FontStyle defaultType)
        {
            string content = LocalDatabase.GetData<LocalizeElement>(DBTag.LOCALIZATION, (int)m_content).text;
            if (string.IsNullOrEmpty(content))
            {
                return string.Empty;
            }

            var result = string.Empty;
            if (defaultColor != m_color)
            {
                result = result.Add("<color=#".Add(ColorUtility.ToHtmlStringRGBA(m_color).Add(">")));
            }

            if (defaultSize != m_size)
            {
                result = result.Add("<size=".Add(m_size.ToString()).Add(">"));
            }

            if (defaultType != m_type)
            {
                switch (m_type)
                {
                    case FontStyle.Bold:
                        result = result.Add("<b>");
                        break;
                    case FontStyle.BoldAndItalic:
                        result = result.Add("<b><i>");
                        break;
                    case FontStyle.Italic:
                        result = result.Add("<i>");
                        break;
                }
            }

            result = result.Add(content);

            if (defaultType != m_type)
            {
                switch (m_type)
                {
                    case FontStyle.Bold:
                        result = result.Add("</b>");
                        break;
                    case FontStyle.BoldAndItalic:
                        result = result.Add("</i></b>");
                        break;
                    case FontStyle.Italic:
                        result = result.Add("</i>");
                        break;
                }
            }

            if (defaultSize != m_size)
            {
                result = result.Add("</size>");
            }

            if (defaultColor != m_color)
            {
                result = result.Add("</color>");
            }

            return result;
        }
    }
}